package com.lintesis.lintesismodel.users;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Vector;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToMany;

import com.lintesis.lintesismodel.common.hibernate.BussinessObject;

@Entity
public class UsrRight extends BussinessObject
{

	@javax.persistence.SequenceGenerator(name = "SEQ_USRRIGHT", sequenceName = "SEQ_USRRIGHT", allocationSize = 1)
	@Id
	@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "SEQ_USRRIGHT")
	private Integer idRight;
	@Column(unique=true)
	private String name;

	@Column(unique = true)
	private String key;
	@ManyToMany
	private List<UsrRight> children;

	
	
	
	@Override
	public String getObjectDescription() {
		String ret="idRight="+idRight+",name="+name;
		return null;
	}

	public UsrRight()
	{
		// children = new ArrayList<UsrRight>();
	}

	public String getKey()
	{
		return key;
	}

	public void setKey(String key)
	{
		this.key = key;
	}

	public Integer getIdRight()
	{
		return idRight;
	}

	public void setIdRight(Integer idRight)
	{
		this.idRight = idRight;
	}

	public String getName()
	{
		return name;
	}

	public void setName(String rightName)
	{
		this.name = rightName;
	}

	@Override
	public Integer getId()
	{
		return getIdRight();
	}

	public List<UsrRight> getChildren()
	{
		return children;
	}

	public void setChildren(List<UsrRight> children)
	{
		this.children = children;
	}

	public void setChildren(HashSet<UsrRight> children)
	{
		if (children != null)
			this.children = new ArrayList<UsrRight>(children);
		else
			this.children = new ArrayList<UsrRight>();
	}

	public Vector<String> getChildrenString()
	{
		Vector<String> ret = new Vector<String>();
		if (children == null)
			return null;
		for (UsrRight permission : children)
		{
			ret.add(permission.getKey());
		}

		return ret;
	}

	public Vector<String> getChildrenNameString()
	{
		Vector<String> ret = new Vector<String>();
		if (children == null)
			return null;
		for (UsrRight permission : children)
		{
			ret.add(permission.getName());
		}

		return ret;
	}

	@Override
	public void doAfterDelete()
	{
		// TODO Auto-generated method stub

	}

	@Override
	public void doAfterSave()
	{
		// TODO Auto-generated method stub

	}

	@Override
	public void doBeforeDelete()
	{
		// TODO Auto-generated method stub

	}

	@Override
	public void doBeforeSave()
	{
		// TODO Auto-generated method stub

	}
}
